package com.zuowei.ycy.user.view;

import android.content.Context;
import android.net.Uri;
import android.view.View;

import com.bigkoo.convenientbanner.holder.Holder;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.generic.GenericDraweeHierarchy;
import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.zuowei.ycy.R;
import com.zuowei.ycy.user.domain.IndexResult;

/**
 *
 */
public class UriImageHolderView implements Holder<IndexResult.AdvertEntity> {

    private SimpleDraweeView imageView;

    @Override
    public View createView(Context context) {
        imageView = new SimpleDraweeView(context);

        GenericDraweeHierarchyBuilder builder =
                new GenericDraweeHierarchyBuilder(context.getResources());
        GenericDraweeHierarchy hierarchy = builder
                .setFadeDuration(300)
                .setPlaceholderImage(context.getResources().getDrawable(R.drawable.ic_banner_default), ScalingUtils.ScaleType.FIT_XY)
                .setFailureImage(context.getResources().getDrawable(R.drawable.ic_banner_default), ScalingUtils.ScaleType.FIT_XY)
                .setActualImageScaleType(ScalingUtils.ScaleType.FIT_XY)
                .build();
        imageView.setHierarchy(hierarchy);

        return imageView;
    }

    @Override
    public void UpdateUI(Context context, final int position, IndexResult.AdvertEntity data) {

        Uri uri = Uri.parse(data.getAd_pic());
        imageView.setImageURI(uri);

    }
}
